package uilts
{
	import flash.display.Loader;
	import flash.errors.IOError;
	import flash.events.Event;
	import flash.events.UncaughtErrorEvent;
	import flash.net.URLRequest;
	
	import interfaces.ILoader;
	
	public class LoadSWF implements ILoader
	{
		private var loadSWF:ILoader;
		private var urlSWF:String;

		private var loader:Loader;
		public function LoadSWF(_loadSWF:ILoader,_urlSWF:String)
		{
			loadSWF = _loadSWF;
			urlSWF = _urlSWF;
			loading();
		}
		
		private function loading():void
		{
			if(loader == null){
				loader = new Loader();
			}
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
			loader.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR,onIOError);
			loader.load(new URLRequest(urlSWF));
		}
		
		public function onComplete(event:Event):void
		{
			trace("SWF加载正确");
			loadSWF.onComplete(event);
		}
		
		public function onIOError(event:IOError):void
		{
			trace("SWF加载错误");
		}
		public function unloadResources():void{
			loader.unloadAndStop();
		}
	}
}